package com.ouc.yyi.controller;

import com.ouc.yyi.config.model.Menu;
import com.ouc.yyi.config.model.SysUser;
import com.ouc.yyi.system.service.MenuService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/test")
public class MenuController {
    @Autowired
    private MenuService menuService;
    @ResponseBody
    @RequestMapping("/menuList")
    public HashMap<String,List<Menu>> getMenu(){
        //获取当前登陆的用户，根据用户的角色找出对应的菜单有哪些
       SysUser sysUser =(SysUser) SecurityUtils.getSubject().getPrincipal();
       List<Menu> menuList = menuService.getMenuByRoleId(sysUser.getRoleId());
       HashMap<String,List<Menu>> hashMap = new HashMap<String,List<Menu>>();
       hashMap.put("data",menuList);
       return hashMap;

    }
}
